//
//  ChartDataCell.swift
//  HuaYun
//
//  Created by Mac on 2019/4/12.
//  Copyright © 2019 xyxorigation. All rights reserved.
//

import UIKit
import Charts
class ChartDataCell: UITableViewCell {
    
    @IBOutlet weak var chart: PieChartView!
    
    private var _model: JSON?
    
    var model: JSON?{
        get{
            return _model
        }
        set{
            _model = newValue
            self.chart.legend.yEntrySpace = 20
            let titles = ["I2事业部","GP事业部","P2事业部","EC事业部","IC事业部","BP事业部","ac事业部","VB事业部"];
            let yData = [1000,2000,3000,4000,5000,6000,7000,8000];
            var yVals = [PieChartDataEntry]();
            for i in 0...titles.count-1 {
                
                let entry = PieChartDataEntry.init(value: Double(yData[i]), label: titles[i]);
                
                yVals.append(entry);
            }
            let dataSet = PieChartDataSet.init(values: yVals, label: "");
            dataSet.colors = [UIColor.init(red: 29 / 255, green: 220 / 255, blue: 113 / 255, alpha: 1),UIColor.hex("8c59d3"),UIColor.hex("eedc63"),UIColor.hex("0bc6f2"),UIColor.hex("ed4a47"),UIColor.hex("dc2378"),UIColor.hex("79ab12"),UIColor.hex("90af12"),UIColor.hex("1234567")];
            //设置名称和数据的位置 都在内就没有折线了哦
            dataSet.xValuePosition = .outsideSlice;
            dataSet.yValuePosition = .outsideSlice;
            dataSet.sliceSpace = 0
            dataSet.selectionShift = 10;//选中放大半径
            dataSet.valueLineVariableLength = false
            dataSet.valueColors = dataSet.colors
            dataSet.valueLinePart1OffsetPercentage = 0.8 //折线中第一段起始位置相对于区块的偏移量, 数值越大, 折线距离区块越远
            dataSet.valueLinePart1Length = 0.4 //折线中第一段长度占比
            dataSet.valueLinePart2Length = 0.4 //折线中第二段长度最大占比
            dataSet.valueLineWidth = 1 //折线的粗细
            dataSet.valueLineColor = UIColor.brown //折线颜色
            let data = PieChartData.init(dataSets: [dataSet]);
            data.setValueFormatter(VDChartAxisValueFormatter.init());//格式化值（添加个%）
            data.setValueFont(UIFont.systemFont(ofSize: 10.0));
            data.setValueTextColor(UIColor.lightGray);
            self.chart.data = data;
        }
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        self.chart.drawHoleEnabled = false
        self.chart.legend.verticalAlignment = .top
        self.chart.legend.orientation = .vertical
        self.chart.chartDescription?.enabled = false
        // Initialization code
    }
    
    
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
